<?php

/**
 * This is the model class for table "prova".
 *
 * The followings are the available columns in table 'prova':
 * @property integer $id
 * @property integer $id_banca
 * @property integer $id_cargo
 * @property integer $id_area
 * @property integer $id_nivel
 * @property integer $ano
 *
 * The followings are the available model relations:
 * @property ProvaNivel $idNivel
 * @property ProvaBanca $idBanca
 * @property ProvaArea $idArea
 * @property ProvaCargo $idCargo
 * @property ProvaAssunto[] $provaAssuntos
 * @property Questao[] $questaos
 */
class Prova extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Prova the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'prova';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('id_banca, id_cargo, id_area, id_nivel, ano', 'required'),
			array('id_banca, id_cargo, id_area, id_nivel, ano', 'numerical', 'integerOnly'=>true),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, id_banca, id_cargo, id_area, id_nivel, ano', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'idNivel' => array(self::BELONGS_TO, 'ProvaNivel', 'id_nivel'),
			'idBanca' => array(self::BELONGS_TO, 'ProvaBanca', 'id_banca'),
			'idArea' => array(self::BELONGS_TO, 'ProvaArea', 'id_area'),
			'idCargo' => array(self::BELONGS_TO, 'ProvaCargo', 'id_cargo'),
			'provaAssuntos' => array(self::HAS_MANY, 'ProvaAssunto', 'id_prova'),
			'questaos' => array(self::HAS_MANY, 'Questao', 'id_prova'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'id_banca' => 'Id Banca',
			'id_cargo' => 'Id Cargo',
			'id_area' => 'Id Area',
			'id_nivel' => 'Id Nivel',
			'ano' => 'Ano',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('id_banca',$this->id_banca);
		$criteria->compare('id_cargo',$this->id_cargo);
		$criteria->compare('id_area',$this->id_area);
		$criteria->compare('id_nivel',$this->id_nivel);
		$criteria->compare('ano',$this->ano);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}